//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package cn.tedu.bonfire.front.content.dao.persist.repository.impl;

import cn.tedu.bonfire.common.pojo.po.TagAdminSearchPO;
import cn.tedu.bonfire.common.pojo.vo.PageData;
import cn.tedu.bonfire.common.util.PageInfoToPageDataConverter;
import cn.tedu.bonfire.front.content.dao.persist.mapper.TagMapper;
import cn.tedu.bonfire.front.content.dao.persist.repository.ITagRepository;
import cn.tedu.bonfire.front.content.pojo.entity.Tag;
import cn.tedu.bonfire.front.content.pojo.vo.TagListStartVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class TagRepositoryImpl implements ITagRepository {
    @Autowired
    private TagMapper tagMapper;

    public TagRepositoryImpl() {
    }

    public int insert(Tag tag) {
        return this.tagMapper.insert(tag);
    }

    public PageData<TagListStartVO> list(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TagListStartVO> tag = this.tagMapper.listTagById();
        PageInfo<TagListStartVO> pageInfo = new PageInfo(tag);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    public PageData<TagAdminSearchPO> listSearchByOrder(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TagAdminSearchPO> tags = this.tagMapper.listSearch();
        PageInfo<TagAdminSearchPO> pageInfo = new PageInfo(tags);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    public Long countByTagName(String tagName) {
        QueryWrapper<Tag> queryWrapper = new QueryWrapper();
        queryWrapper.eq("tag_name", tagName);
        return this.tagMapper.selectCount(queryWrapper);
    }
}
